 import axios from 'axios';
 import cookie from 'react-cookies'
 import {createHashHistory} from "history";
 import {showErrorMessage, showSuccessMessage} from "@iso/containers/Feedback/Message/MessageUtils";
 /**
  * Do something  before sending request
  */
 axios.interceptors.request.use(
     config => {

         config.headers['Authorization'] = 'Basic enV1bF9zZXJ2ZXI6c2VjcmV0';

         let access_token=cookie.load('access_token')

         if (access_token==undefined){
             return config
         }

             config.params = {
                 "access_token":access_token,
                 ...config.params
             }


         return config;
     },
     error => {
         return Promise.error(error);
     }
 )
 /**
  * Do something before handling response
  */
 axios.interceptors.response.use(response=>{
     return response;
 },error => {
     if(error.response.status === 401){
         let history = createHashHistory()
         history.push({
             pathname: "/"
         });
         history.go();
     }
     if(error.response.status === 403){
         showErrorMessage("拒绝访问！");

     }
     return Promise.resolve(error.response)
 });

 export default axios;
